package entity;

public class SuperPackage extends BrandPackage implements CallService,NetService,SendService{//超人套餐类
    private int talkTime = 200;
    private int messageCount = 50;
    private int flow = 1024;

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getMessageCount() {
        return messageCount;
    }

    public void setMessageCount(int messageCount) {
        this.messageCount = messageCount;
    }

    public int getFlow() {
        return flow;
    }

    public void setFlow(int flow) {
        this.flow = flow;
    }

    public SuperPackage() {
    }

    public SuperPackage(double price, int talkTime, int messageCount, int flow) {
        super(price);
        this.talkTime = talkTime;
        this.messageCount = messageCount;
        this.flow = flow;
    }

    public SuperPackage(double price) {
        super(price);
    }

    @Override
    public void show() {
        System.out.println("超人套餐：通话时长：" + talkTime + "分钟，短信数量：" + messageCount + "个，上网流量" + flow + "MB，资费：" + getPrice() + "元");
    }

    @Override
    public int call(int minCount, MobileCard card) throws Exception {//用于当使用嗖嗖后，产生的费用和卡内通话分钟数的更改及余额超出时的提醒
        int tempMin = 0;
        for (int i = 1; i <= minCount; i++) {
            tempMin++;
            if ((talkTime - card.getRealTalkTime()) >= 1){
                card.setRealTalkTime((card.getRealTalkTime() + 1));
            }else if(card.getMoney() >= 0.2){
                card.setMoney((card.getMoney() - 0.2));
                card.setRealTalkTime((card.getRealTalkTime() + 1));
                card.setConsume(card.getConsume() + 0.2);
            }else {
                throw new Exception("本次通话" + tempMin + "分钟，你的余额不足，请充值！");
            }
        }
        return  tempMin;
    }

    @Override
    public int netPlay(int flow, MobileCard card) throws Exception {//与call相似，只不过是对卡内流量的更改
        int tempFlow = 0;
        for (int i = 0; i < flow; i++) {
            tempFlow++;
            if ((this.flow - card.getRealFlow()) >= 1) {
                card.setRealFlow(card.getRealFlow() + 1);
            }else if (card.getMoney() >= 0.1) {
                card.setMoney(card.getMoney() - 0.1);
                card.setRealFlow(card.getRealFlow() + 1);
                card.setConsume(card.getConsume() + 0.1);
            }else {
                throw new Exception("本次上网已用" + tempFlow + "MB流量，余额不足请立即充值");
            }
        }
        return tempFlow;
    }

    @Override
    public int send(int count, MobileCard card) throws Exception {//与call相似，只不过是对卡内短信数量的更改
        int tempMassage = 0;
        for (int i = 0; i < count; i++) {
            tempMassage++;
            if ((messageCount - card.getRealMassageNumbers()) >= 1) {
                card.setRealMassageNumbers((card.getRealMassageNumbers() + 1));
            }else if (card.getMoney() >= 0.1) {
                card.setMoney(card.getMoney() - 0.1);
                card.setRealMassageNumbers((card.getRealMassageNumbers() + 1));
                card.setConsume(card.getConsume() + 0.1);
            }else{
                throw new Exception("本次发短信" + tempMassage + "次，你的余额不足，请充值！");
            }
        }
        return tempMassage;
    }
}
